package com.hxz.graduationdesign.controller;

import com.hxz.graduationdesign.base.response.JsonResult;
import com.hxz.graduationdesign.base.response.StatusCode;
import com.hxz.graduationdesign.pojo.vo.UserVo;
import com.hxz.graduationdesign.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("/v1/user/")
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("query/{uid}")
    public JsonResult queryUser(@PathVariable String uid){
        log.debug("查询用户uid："+uid);

        UserVo userVo = userService.queryUser(uid);
        return userVo!=null?JsonResult.ok(userVo):new JsonResult(StatusCode.USER_ADD_FAILED);

    }

    @PostMapping("update/{uid}")
    public JsonResult update(@PathVariable String uid){
        log.debug("更新用户uid：{}",uid);
        UserVo update = userService.update(uid);
        return JsonResult.ok(update);
    }

}
